package com.xinwei.leetcode.数组;

/**
 *  https://leetcode-cn.com/problems/remove-duplicates-from-sorted-array/
 *  删除有序数组中的重复项
 */
public class _26_删除有序数组中的重复项 {


    public static void main(String[] args) {
        int[] nums = new int[]{0,0,1,1,1,2,2,3,3,4};
        int left = 0;
        for (int right = 1; right < nums.length; right++) {
            if (nums[right] != nums[left]) {
                nums[++left] = nums[right];
            }
        }
        StringBuilder builder = new StringBuilder();
        builder.append("[");
        for (int i = 0; i <= left; i++) {
            if (i < left) {
                builder.append(nums[i] + ",");
            }else {
                builder.append(nums[i]);
            }
        }
        builder.append("]");
        System.out.println(builder.toString());


        System.out.println("size为"+(++left));
    }
}
